import { Component, OnInit } from '@angular/core'
import { IChargeBack, EChargeBackStatus, EChargeBackTransCode } from '@shared/interfaces/operation'
import { NzMessageService } from 'ng-zorro-antd'
import { I18NService } from '@core'
import { Router, ActivatedRoute } from '@angular/router'
import { OperationsService } from '../../operations-abstract.service'

@Component({
  selector: 'app-operation-charge-back-detail',
  templateUrl: './detail.component.html'
})
export class ChargeBackDetailComponent implements OnInit {
  detail: IChargeBack

  EChargeBackTransCode = EChargeBackTransCode
  EChargeBackStatus = EChargeBackStatus

  constructor(
    private i18n: I18NService,
    private msg: NzMessageService,
    private router: Router,
    private route: ActivatedRoute,
    private operateService: OperationsService,
  ) {}

  ngOnInit() {
    const { disputeNum } = this.route.snapshot.params
    this.getDetail(disputeNum)
  }

  getDetail(disputeNum: string): void {
    this.operateService.getChargeBackOne(disputeNum).subscribe(
      (detail) => {
        this.detail = detail
      },
      err => {
        this.msg.error(this.i18n.fanyi('OPERATION.ERROR.SEARCH_FAIL'))
      }
    )
  }
}
